home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Main.bin / Option.java < prev    next >
Text File  |  1998-09-08  |  5KB  |  267 lines

  1. package com.symantec.itools.frameworks.application.commandline;
  2.  
  3.  
  4. /**
  5.  * @author Symantec Internet Tools Division
  6.  * @version 1.0
  7.  * @since VCafe 3.0
  8.  */
  9.  
  10. public abstract class Option
  11. {
  12.  
  13.     /**
  14.      * @since VCafe 3.0
  15.      */
  16.     protected String[] flags;
  17.  
  18.     /**
  19.      * @since VCafe 3.0
  20.      */
  21.     protected String[] defaultValues;
  22.  
  23.     /**
  24.      * @since VCafe 3.0
  25.      */
  26.     protected boolean  called;
  27.  
  28.     /**
  29.      * @since VCafe 3.0
  30.      */
  31.     protected boolean  hasDefault;
  32.  
  33.     /**
  34.      * @since VCafe 3.0
  35.      */
  36.     protected boolean  isMandatory;
  37.  
  38.     /**
  39.      * @since VCafe 3.0
  40.      */
  41.     protected String   shortDesc;
  42.  
  43.     /**
  44.      * @since VCafe 3.0
  45.      */
  46.     protected String   longDesc;
  47.  
  48.     /**
  49.      * @since VCafe 3.0
  50.      */
  51.     protected String   help;
  52.     
  53.     protected Option()
  54.     {
  55.         flags         = new String[0];
  56.         defaultValues = new String[0];
  57.     }
  58.     
  59.     protected Option(String[] f)
  60.     {
  61.         flags = f;
  62.     }
  63.  
  64.     /**
  65.      * @param f TODO
  66.      * @since VCafe 3.0
  67.      */
  68.     
  69.     public void setFlags(String[] f)
  70.     {
  71.         flags = f;
  72.     }
  73.  
  74.     /**
  75.      * @since VCafe 3.0
  76.      */
  77.     
  78.     public String[] getFlags()
  79.     {
  80.         return (flags);
  81.     }
  82.  
  83.     /**
  84.      * @since VCafe 3.0
  85.      */
  86.     
  87.     public String toString()
  88.     {
  89.         return (shortDesc);
  90.     }
  91.  
  92.     /**
  93.      * @since VCafe 3.0
  94.      */
  95.     
  96.     public boolean wasCalled()
  97.     {
  98.         return (called);
  99.     }
  100.  
  101.     /**
  102.      * @param f TODO
  103.      * @since VCafe 3.0
  104.      */
  105.     
  106.     public void setCalled(boolean f)
  107.     {
  108.         called = f;
  109.     }
  110.  
  111.     /**
  112.      * @param f TODO
  113.      * @since VCafe 3.0
  114.      */
  115.     
  116.     public void setMandatory(boolean f)
  117.     {
  118.         isMandatory = f;
  119.     }
  120.  
  121.     /**
  122.      * @since VCafe 3.0
  123.      */
  124.     
  125.     public boolean isMandatory()
  126.     {
  127.         return (isMandatory);
  128.     }
  129.  
  130.     /**
  131.      * @since VCafe 3.0
  132.      */
  133.     
  134.     public boolean hasDefault()
  135.     {
  136.         return (hasDefault);
  137.     }
  138.  
  139.     /**
  140.      * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  141.      * @since VCafe 3.0
  142.      */
  143.     
  144.     public void parseDefault()
  145.         throws InvalidArgumentException
  146.     {
  147.         setCalled(true);
  148.         parseArg(defaultValues, 0);
  149.     }    
  150.  
  151.     /**
  152.      * @param str TODO
  153.      * @since VCafe 3.0
  154.      */
  155.     
  156.     public void setDefaultValue(String str)
  157.     {
  158.         if(str == null)
  159.         {
  160.             return;
  161.         }
  162.         
  163.         hasDefault       = true;        
  164.         defaultValues    = new String[2];
  165.         defaultValues[1] = str;
  166.     }    
  167.  
  168.     /**
  169.      * @param array TODO
  170.      * @since VCafe 3.0
  171.      */
  172.     
  173.     public void setDefaultValue(String[] array)
  174.     {
  175.         if(array.length == 0)
  176.         {
  177.             return;
  178.         }
  179.         
  180.         hasDefault    = true;
  181.         defaultValues = new String[array.length + 1];
  182.         System.arraycopy(array, 0, defaultValues, 1, array.length);
  183.     }   
  184.  
  185.     /**
  186.      * @since VCafe 3.0
  187.      */
  188.     
  189.     public String[] getDefaultValue()
  190.     {
  191.         return (defaultValues);
  192.     }
  193.  
  194.     /**
  195.      * @since VCafe 3.0
  196.      */
  197.     
  198.     public String getShortDesc()
  199.     {
  200.         return (shortDesc);
  201.     }
  202.  
  203.     /**
  204.      * @since VCafe 3.0
  205.      */
  206.     
  207.     public String getLongDesc()
  208.     {
  209.         return (longDesc);
  210.     }
  211.  
  212.     /**
  213.      * @param str TODO
  214.      * @since VCafe 3.0
  215.      */
  216.     
  217.     public void setShortDesc(String str)
  218.     {
  219.        shortDesc = str;
  220.     }
  221.  
  222.     /**
  223.      * @param str TODO
  224.      * @since VCafe 3.0
  225.      */
  226.     
  227.     public void setLongDesc(String str)
  228.     {
  229.        longDesc = str;
  230.     }
  231.  
  232.     /**
  233.      * @param str TODO
  234.      * @since VCafe 3.0
  235.      */
  236.     
  237.     public void setHelp(String str)
  238.     {
  239.         help = str;
  240.     }
  241.  
  242.     /**
  243.      * @since VCafe 3.0
  244.      */
  245.     
  246.     public String getHelp()
  247.     {
  248.         return (help);
  249.     }
  250.  
  251.     /**
  252.      * @param args TODO
  253.      * @param startIndex TODO
  254.      * @exception com.symantec.itools.frameworks.application.commandline.InvalidArgumentException
  255.      * @since VCafe 3.0
  256.      */
  257.     
  258.     public abstract void parseArg(String[] args, int startIndex) 
  259.         throws InvalidArgumentException;
  260.  
  261.     /**
  262.      * @since VCafe 3.0
  263.      */
  264.     protected abstract int getConsumedCount();    
  265. }
  266.  
  267.